/**
 * CourseDetailsModule.java
 * com.sftz.modules.minapp.coursedetails.module
 * Copyright (c) 2018, 北京科技有限公司版权所有.
*/

package com.sftz.modules.minapp.coursedetails.module;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import com.sftz.framework.rersult.MobileResult;
import com.sftz.modules.minapp.coursedetails.form.CourseDetailsForm;
import com.sftz.modules.minapp.coursedetails.form.WebCourseCommentForm;
import com.sftz.modules.minapp.coursedetails.service.CourseDetailsViewService;

/**
 * @author   闫志彬
 * @Date	 2018年12月13日 	 
 */
@IocBean
@At("/wx/coursedetails")
public class CourseDetailsModule {

	@Inject
	private CourseDetailsViewService courseDetailsViewService;

	/**
	 * 查询课程封面
	 */
	@At
	@Ok("json")
	public Object getCoursePicture(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object coursePicture = courseDetailsViewService.getCoursePicture(courseDetailsForm);
			return MobileResult.success("", coursePicture);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 查询课程信息
	 */
	@At
	@Ok("json")
	public Object getCourseInfor(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object courseInfor = courseDetailsViewService.getCourseInfor(courseDetailsForm);
			return MobileResult.success("", courseInfor);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 查询用户是否购买过该课程决定是否可点击章节列表
	 */
	@At
	@Ok("json")
	public Object canClickCourseSturcture(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object canClickCourseSturcture = courseDetailsViewService.canClickCourseSturcture(courseDetailsForm);
			return MobileResult.success("", canClickCourseSturcture);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 查询课程教师信息
	 */
	@At
	@Ok("json")
	public Object getTeacherInfor(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object teacherInfor = courseDetailsViewService.getTeacherInfor(courseDetailsForm);
			return MobileResult.success("", teacherInfor);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 查询用户对课程报名、收藏、点赞等状态信息
	 */
	@At
	@Ok("json")
	public Object getCourseUserInfor(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object courseUserInfor = courseDetailsViewService.getCourseUserInfor(courseDetailsForm);
			return MobileResult.success("", courseUserInfor);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 查询课程大纲信息
	 */
	@At
	@Ok("json")
	public Object getCourseOutline(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object courseOutline = courseDetailsViewService.getCourseOutline(courseDetailsForm);
			return MobileResult.success("", courseOutline);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 点赞
	 */
	@At
	@Ok("json")
	public Object courseLike(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object courseLike = courseDetailsViewService.courseLike(courseDetailsForm);
			return MobileResult.success("", courseLike);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 点收藏
	 */
	@At
	@Ok("json")
	public Object courseCollect(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object courseCollect = courseDetailsViewService.courseCollect(courseDetailsForm);
			return MobileResult.success("", courseCollect);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 立即报名
	 */
	@At
	@Ok("json")
	public Object courseEnroll(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object courseEnroll = courseDetailsViewService.courseEnroll(courseDetailsForm);
			return MobileResult.success("", courseEnroll);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 根据课程id 去查询DIY资料包集合
	 */
	@At
	@Ok("json")
	public Object findCourseDIYResourceList(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object findCourseDIYResourceList = courseDetailsViewService.findCourseDIYResourceList(courseDetailsForm);
			return MobileResult.success("", findCourseDIYResourceList);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 根据DIY资料包id 去查询资料列表
	 */
	@At
	@Ok("json")
	public Object findCourseDIYResourceDetailsList(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object findCourseDIYResourceDetailsList = courseDetailsViewService
					.findCourseDIYResourceDetailsList(courseDetailsForm);
			return MobileResult.success("", findCourseDIYResourceDetailsList);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 根据DIY资料包具体资料id 去查询内容信息
	 */
	@At
	@Ok("json")
	public Object findCourseDIYResourceDetailsContent(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object findCourseDIYResourceDetailsContent = courseDetailsViewService
					.findCourseDIYResourceDetailsContent(courseDetailsForm);
			return MobileResult.success("", findCourseDIYResourceDetailsContent);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}

	/**
	 * 判断当前课程是否可以评价
	 * @param sqlParamForm-haozhenbin
	 * @param session
	 */
	@At
	@Ok("json")
	public Object evaluateIf(@Param("..") final WebCourseCommentForm sqlParamForm) {
		return courseDetailsViewService.evaluateIf(sqlParamForm);
	}

	/**
	 * 课程评价保存
	 * @param sqlParamForm-haozhenbin
	 * @param session
	 */
	@At
	@Ok("json")
	public Object courseComment(@Param("..") final WebCourseCommentForm sqlParamForm) {
		return courseDetailsViewService.saveComment(sqlParamForm);
	}

	/**
	 * 查询当前是否有24小时之内未支付的课程订单
	 */
	@At
	@Ok("json")
	public Object findUnpaidCourseInTwentyfourHours(@Param("..") final CourseDetailsForm courseDetailsForm) {
		try {
			Object findUnpaidCourseInTwentyfourHours = courseDetailsViewService
					.findUnpaidCourseInTwentyfourHours(courseDetailsForm);
			return MobileResult.success("", findUnpaidCourseInTwentyfourHours);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("", "");
		}
	}
}
